﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using EasySL.Controls;

namespace EasySL.UI.Controls
{
    public partial class ExDataGridSample : UserControl
    {
        public ExDataGridSample()
        {
            InitializeComponent();

            Random rd = new Random();

            List<NoteBook> products = new List<NoteBook>();
            for (int i = 1; i < 30; i++)
            {
                NoteBook product = new NoteBook();
                product.Name = "P" + (1000 + i).ToString();
                product.Price = rd.Next(100, 400);
                product.Price1 = rd.Next(50, 60);
                product.Price2 = product.Price - product.Price1;
                product.Rate = Convert.ToDouble(rd.Next(10000, 99999)) / 100000;
                product.Category = "C" + (1000 + i).ToString();
                product.Introduce = "I" + (1000 + i).ToString();
                product.Url = "http://www.google.com/search?&q=" + product.Introduce;

                products.Add(product);
            }

            this.dg.Loaded += (s, e) => this.dg.ItemsSource = products;

            this.dg.OnChecked += r =>
            {
                this.checkedInfo.Text = string.Format("{0}, u checked item: {1} to {2}\r\n{3}", DateTime.Now, r["Name"], r.IsChecked, this.checkedInfo.Text);
            };

            this.dg.BindDragItems(this.dragItems.Children);
        }

        private void ExDataGridStringColumn_Click(object sender, DataRowEventArgs e)
        {
            this.checkedInfo.Text = e.Data["Name"].ToString();
        }
    }

    public class NoteBook
    {
        public string Name { get; set; }
        public int Price { get; set; }
        public int Price1 { get; set; }
        public int Price2 { get; set; }
        public double Rate { get; set; }
        public string Category { get; set; }
        public string Introduce { get; set; }
        public string Url { get; set; }
    }
}
